from sqlalchemy import create_engine, Integer, String, Float, DateTime, Text
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column

# 数据库账号
user_name = 'root'
# 数据库密码
pass_word = '123'
# 数据库ip地址
id_num = '127.0.0.1'
# 具体使用数据库的库名
database = 'test'

# 创建数据库连接
engine = create_engine(f"mysql+pymysql://{user_name}:{pass_word}@{id_num}:3306/{database}?charset=utf8")
# 操作数据库前创建session
Session = sessionmaker(bind=engine)
# 声明一个基类
Base = declarative_base()


# 列表信息
class DataList(Base):
	# 表名
	__tablename__ = 'Data_List'
	__table_args__ = {
		'mysql_charset': 'utf8'
	}
	# id,主键并且自动增长
	id = Column(Integer, primary_key=True, autoincrement=True)

	# positionName = Column(Text, nullable=True)
	AREACODE = Column(String(length=255), nullable=True)
	AREA_CODE_TEXT = Column(String(length=255), nullable=True)
	CATAID = Column(String(length=255), nullable=True)
	CATANAME = Column(String(length=255), nullable=True)
	DEPT_NAME = Column(String(length=255), nullable=True)
	LIMIT_SCENE_NUM = Column(String(length=255), nullable=True)
	ONLINECHECK = Column(String(length=255), nullable=True)
	ORGCODE = Column(String(length=255), nullable=True)
	TASK_CODE = Column(String(length=255), nullable=True)
	TASK_NAME = Column(String(length=255), nullable=True)
	TASK_STATE = Column(String(length=255), nullable=True)
	TASK_TAG = Column(String(length=255), nullable=True)
	TASK_TYPE = Column(String(length=255), nullable=True)
	TASK_TYPE_TEXT = Column(String(length=255), nullable=True)
	URL = Column(String(length=255), nullable=True)
	parentCatalogId = Column(String(length=255), nullable=True)
	parentCatalogName = Column(String(length=255), nullable=True)
	subCatalogName = Column(String(length=255), nullable=True)
	subTaskName = Column(String(length=255), nullable=True)
	Item_types = Column(String(length=255), nullable=True, comment='事项类型')
	Guide_to = Column(String(length=255), nullable=True, comment='办事指南')
	Update_tag = Column(String(length=255), nullable=True, comment='全量数据,增量数据')
	# 创建时间
	gmt_create = Column(DateTime, nullable=True, comment='创建时间')


# 基本信息表
class DataInfo(Base):
	# 表名
	__tablename__ = 'Data_Info'
	__table_args__ = {
		'mysql_charset': 'utf8'
	}
	# id,主键并且自动增长
	id = Column(Integer, primary_key=True, autoincrement=True)

	# positionName = Column(Text, nullable=True)
	index_id = Column(Integer, nullable=True)
	json_data = Column(Text, nullable=True)


if __name__ == '__main__':
	# 创建数据表
	DataList.metadata.create_all(engine)
	DataInfo.metadata.create_all(engine)
	print('成功')
